package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.activity.InvestPingLunAuthor;
import com.zzk.lanouhn.myapplication1.modles.InvestPingLunAuthorFenSiModle;

import java.util.ArrayList;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by lanouhn on 16/9/18.
 */
public class InvestPingLunAuthorFenSiAdapter extends RecyclerView.Adapter<InvestPingLunAuthorFenSiAdapter.MyHorld> {

    private Context context;
    private List<InvestPingLunAuthorFenSiModle.DataBean.FanDataBean> fanDataBeen = new ArrayList<>();

    public InvestPingLunAuthorFenSiAdapter(Context context, List<InvestPingLunAuthorFenSiModle.DataBean.FanDataBean> fanDataBeen) {
        this.context = context;
        this.fanDataBeen = fanDataBeen;
    }

    @Override
    public MyHorld onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_invest_pinglun_author_fensi, null);
        MyHorld horld = new MyHorld(view);
        return horld;
    }

    @Override
    public void onBindViewHolder(MyHorld holder, final int position) {

        Picasso.with(context).load(fanDataBeen.get(position).getAvatar_small()).into(holder.civ_touxiang);

        holder.tv_zuozhe.setText(fanDataBeen.get(position).getNickname());

        if (fanDataBeen.get(position).getUser_lol_info() == null) {
            holder.tv_nicheng.setText("游戏资料未绑定");
            holder.tv_qu.setVisibility(View.GONE);
            holder.tv_zdl.setVisibility(View.GONE);
        } else {
            holder.tv_nicheng.setText(fanDataBeen.get(position).getUser_lol_info().getSummoner());
            holder.tv_qu.setText(fanDataBeen.get(position).getUser_lol_info().getArea());
            holder.tv_zdl.setText("战斗力 " + fanDataBeen.get(position).getUser_lol_info().getZdl());
        }

        if (fanDataBeen.get(position).getSex().equals("1")) {
            holder.iv_nan.setVisibility(View.VISIBLE);
            holder.iv_nv.setVisibility(View.GONE);
        } else {
            holder.iv_nv.setVisibility(View.VISIBLE);
            holder.iv_nan.setVisibility(View.GONE);
        }
        //跳转到评论人的页面
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String userID = fanDataBeen.get(position).getUserid();
                Intent intent = new Intent(context, InvestPingLunAuthor.class);
                intent.putExtra("FenSiID", userID);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return fanDataBeen.size();
    }

    public class MyHorld extends RecyclerView.ViewHolder {

        private CircleImageView civ_touxiang;
        private TextView tv_zuozhe, tv_nicheng, tv_qu, tv_zdl;
        private ImageView iv_nan, iv_nv;

        public MyHorld(View itemView) {
            super(itemView);
            civ_touxiang = (CircleImageView) itemView.findViewById(R.id.pinglun_author_fensi_touxiang);

            tv_zuozhe = (TextView) itemView.findViewById(R.id.pinglun_author_fensi_zuozhe);
            tv_nicheng = (TextView) itemView.findViewById(R.id.pinglun_author_fensi_nicheng);
            tv_qu = (TextView) itemView.findViewById(R.id.pinglun_author_fensi_qu);
            tv_zdl = (TextView) itemView.findViewById(R.id.pinglun_author_fensi_zdl);

            iv_nv = (ImageView) itemView.findViewById(R.id.pinglun_author_fensi_iv_NV);
            iv_nan = (ImageView) itemView.findViewById(R.id.pinglun_author_fensi_iv_Nan);

        }
    }
}
